## 11.4. X Applications

There are thousands of programs available for X. They range from basic utilities (such as `xterm` and `xclock`, already discussed) to editors to programming aids to games to multimedia applications. The most we can provide here is a tiny slice of the software available for X. In this section, we'll present those applications that all X users should know how to use. These aren't necessarily the most exciting programs out there, but they should certainly be part of your toolbox. Note that if you are using a desktop environment such as KDE, described in the last section, it may have tools of its own that do the same things as the ones described here, but work better with the desktop. The general techniques described here usually apply to the desktop tools as well.

A more comprehensive explanation of X applications can be found in X Window System User's Guide.

### 11.4.1. xterm: Your Home Base

Let's start our exploration of X applications with the workhorse that you'll be spending most of your time with--`xterm`. This is simply a window that contains a Unix shell. It displays a prompt, accepts commands, and scrolls like a terminal.

> #### NOTE

> If you use KDE, you can also use KDE's own terminal emulator `kvt`, which provides more or less the same features as `xterm`, but can be configured via a user-friendly GUI.

Perhaps you are struck by the irony of buying a high-resolution color monitor, installing several megabytes of graphics software, and then being confronted by an emulation of an old VT100 terminal. But Linux is simply not a point-and-click operating system. There are plenty of nice graphical applications, but a lot of the time you'll want to manipulate text, and a command-line interface still offers the most powerful tools for doing that.

So let's take look at an `xterm` window. Figure 11-6 shows one where we've already entered a few commands. By the way, if you've read the section "Section 11.1, "Basics of X Customization"" earlier in this chapter, you may enjoy browsing some of the files in /usr/lib/X11/app-defaults; they show the default behavior of X applications when you don't specify your own preferences.

#### Figure 11-6. xterm window

### 11.4.2. Starting up xterm

Maybe first we should explain how we created the `xterm` window. You can reproduce it through the command:

>     eggplant$ xterm  -geometry 80x25-20-30  -fn 7x13bold  -sb  -name xterm-3

where the options mean:

-geometry 80x25-20-30

  The window is 80 characters wide and 25 characters high, located 20 pixels from the right edge of the screen and 30 pixels from the bottom edge.

-fn 7x13bold

  Text appears in a medium-sized bold font. (A large, but limited, set of fonts are available; we'll show you how to look at them later, in the section "Section 11.4.5, "Choosing Fonts".")

-sb

  A scrollbar is displayed.

-name xterm-3

  The string `xterm-3` appears in the titlebar at the top of the window, and on the icon when you iconify the window.

But you don't want to go to the trouble of entering this long command every time you start an `xterm`. What we did (as you can see in the earlier section "Section 11.1, "Basics of X Customization"") was put the following options in our .Xdefaults file:

>      ! Defaults for all xterm clients
>       XTerm*scrollBar:        true

>      ! Specific xterms
>       xterm-3*Geometry:       80x25-20-30

>       xterm-3*Font:           7x13bold

and when we logged in, our .xinitrc file issued the command:

>     xterm -name "xterm-3" &

which created the window. As you saw in the section "The fvwm Window Manager" earlier in this chapter, you can easily set up a menu, mouse button, function key, and so on, to start the `xterm`.

To close a window, type `exit` or press Ctrl-D. If this capability seems dangerous to you (because you could lose your window by pressing Ctrl-D accidentally), start up the `xterm` with the -ls option, which stands for login shell. Now you have to enter `logout` to close the window. (The option has some other consequences, too. In the `bash` shell, it causes your ~/.bash_profile file to run. In the C shell, it causes your ~/.login file to run.)

### 11.4.3. Cutting and Pasting Selections

Actually, `xterm` offers a good deal more than a VT100 terminal. One of its features is a powerful cut-and-paste capability.

Take another look at Figure 11-1. Let's say we didn't really want the app-defaults directory; we wanted to look at the fonts in /usr/lib/X11/fonts instead. (This is actually not too interesting; it was an arbitrary choice.)

First, we'll choose the part of the `cd` command that interests us. Put the mouse just to the left of the `c` in `cd`. Press the left mouse button, and drag the mouse until it highlights the slash following `X11`. The result is shown in Figure 11-7.

Did you include too many characters or too few? That's all right; just hold down the Shift key and press the left mouse button anywhere in the highlighted area. Now you can make the highlighted area bigger or smaller.

#### Figure 11-7. Selected text in xterm

When the highlighted area covers just the right number of characters, click the middle button. `xterm` pastes in what you've selected on the next command line. See the result in Figure 11-8.

#### Figure 11-8. xterm window after text is pasted

Now you can type in the remainder of the directory name fonts and press the Enter key to execute the command.

You can select anything you want in the window--output as well as input. To select whole words instead of characters, double-click the left mouse button. To select whole lines, triple-click it. You can select multiple lines too. Selecting multiple lines is not useful when you're entering commands but is convenient if you're using the `vi` editor and want to cut and paste a lot of text between windows.

Be careful: if a long line wraps around, you will end up with a newline in the selection even though you didn't press the Enter key when you entered the line.

### 11.4.4. Scrolling

Eventually, as you type along in your `xterm`, previous commands will scroll off the top of the window. That's why we specified a scrollbar when we started the `xterm`. Using it is pretty simple (as it ought to be with any point-and-click tool), but there are a few neat tricks. By the way, the techniques you learn here should work in most applications that offer scrollbars. An X application is free to act any way the programmer designed it to, but most developers use the same conventions as `xterm`.

First, let's get a lot of text into our window. Issuing one of the following commands should suffice:

>     eggplant$ ls /bin
>     eggplant$ ls /usr/bin
>     eggplant$ cat ~/.*

Of course, the output will go streaming by too fast for you to see it. Now we can go back and look at it. If you examine the scrollbar area on the left side of the window, you'll see a little dark area near the bottom. Its size indicates how much of the output you can currently see, and its position shows you where you are (at the end).

Place the mouse in the scrollbar area near the bottom, and press the right mouse button. This moves you one whole page upward; what used to be at the top of the screen is now at the bottom. If you click near the top of the screen, you move back by just a couple lines. If you click near the middle, you move back half a window at a time. Notice that the scrollbar moves up as you click the button.

To go back down, click the left mouse button. Again, clicking near the top moves you just a couple lines, while clicking near the bottom moves you a full window's length.

When you have a really big buffer of saved material, you may want to go to the beginning or end really fast; that's what the middle mouse button is good for. Click anywhere in the scrollbar area, and you'll go to that part of the buffer. Therefore, click at the top to go to the beginning, and at the bottom to go to the end. Or click right on the scrollbar itself, hold down the button, and drag the scrollbar where you want to go.

If you're a keyboard kind of person, you don't need to use the mouse to scroll. You can also hold down the Shift key and press the Page Up key to scroll backward, or the Page Down key to scroll forward. By the way, the keys work the same in a virtual console (see the section "Section 4.3, "Virtual Consoles"" in Chapter 4, "Basic Unix Commands and Concepts").

You'll find that `xterm` does not save much output by default. To increase the number of lines that are saved, use the -sl number option or put an entry like the following in your .Xdefaults file:

>     XTerm*saveLines:                400

### 11.4.5. Choosing Fonts

Think your fonts are ugly or too small? There are plenty of others to choose from. Virtually every X application lets you choose the font used to display each kind of text (menus, and so on). You just have to know what their names are and what they look like.

A desktop, as described earlier in this chapter, gives you a simple and intuitive way to choose a font. If you're not using a desktop, you can at least view fonts using the `xfontsel` and `xfd` utilities. But after you find a font you like, you must copy it into .Xdefaults or do whatever else you have to to configure an application.

Fonts on the X Window System have incredibly long names. A typical one is:

>     -misc-fixed-bold-r-normal--13-100-100-100-c-70-iso8859-1

The hyphens divide the fonts into fields. For now, what interests us most is the field following the eleventh hyphen, where we see `c` in this example.

For `xterm` and many other applications, what you need is a monospaced font. That means a font where every character takes up the same amount of space, as opposed to proportional fonts, where an `m` is wider than an `i`. Proportional fonts are great for displaying the output of a text processor like TeX, but they look horrible when used in a program that's not designed to handle the variety of spacing. When the eleventh field of the font name is `c` or `m`, it represents a monospaced font.

Other fields can also help you make a choice. The third field tells you whether the font is medium (which means normal weight) or bold. The seventh field, which says 13 in this example, gives you the size (actually the height of the largest character in pixels).

Now let's see whether our system has a font with the size and style we want. Start the utility `xfontsel` from a command line in an `xterm` window. It loads all the fonts on your system and displays a screen where you make your selection. You can also restrict the fonts to ones of particular interest, but the syntax of the command is rather daunting because any field you don't specify explicitly must be specified as an asterisk:

>     eggplant$ xfontsel -pattern -*-*-bold-*-*-*-18-*-*-*-m-*-*

A typical `xfontsel` display looks like Figure 11-9.

#### Figure 11-9. xfontsel to show fonts

Each of the strings such as `wght` and `slant` represents a part of the font name. The font name in our earlier example has a weight of `bold` and a slant of `r` which stands for roman. The eleventh field is `spc`, but we want to be `c` or m. So, put your mouse on the `spc` field, press the left mouse button to display a menu, and select either `c` or `m` from the menu. You can then try other fields (to select a size, choose from the ptSz menu) and view a font matching your specification.

An older way of checking available fonts is to use the `xlsfonts` command. Just as `ls` lists files, `xlsfonts` lists fonts. But if you enter the command without arguments, the volume of output will overwhelm you. It's better to figure out what types of fonts you need and just look at those.

In `xlsfonts`, you specify a font through the -fn option and use an asterisk to match an arbitrary set of characters. If we want to match the third and eleventh fields exactly, and don't care what the other fields are, we enter:

>     eggplant$ xlsfonts -fn -*-*-bold-*-*-*-*-*-*-*-m-*-*

This tells `xlsfonts` that the first and second fields can be anything. But the third must be bold. The eleventh is also specified; it's an `m`. What we'll see is a list of monospaced bold fonts. If none exist, we'll get the message: `g`:

>     xlsfonts: pattern "-*-*-bold-*-*-*-*-*-*-*-m-*-*" unmatched

Now replace the `m` with a `c` and look for the rest of the monospaced fonts.

Actually, you don't have to use such complicated names. In our examples earlier in the chapter, we specified the short name `7x13bold`. That kind of name is called an alias; it represents another name of the longer type. To see a short list of monospaced fonts using these aliases, enter:

>     eggplant$ xlsfonts *x*

We've gone through a fair amount of trouble already, and all we have is a list of names. What do fonts actually look like? The `xfontsel` shows you the letters and digits from a font. If you want to see every character in the font, use the `xfd` command, which stands for "X font display." It displays a grid with one rectangle for each character:

>     eggplant$ xfd -fn -misc-fixed-bold-r-normal--13-100-100-100-c-70-iso8859-1

When you find a font you like, cast it in concrete by putting it in your .Xdefaults file:

>     XTerm*Font:           7x13bold

### 11.4.6. Clocks

How can your screen be complete if it is unadorned by a little clock that tells you how much time you are wasting on customizing the screen's appearance? You can have a clock just the way you want it, square or round, analog or digital, big or small. You can even make it chime.

The .xinit file shown earlier in this chapter contains a line that starts `oclock`:

>     oclock -geometry 70x70+5+5 &

Refer to Figure 11-1 to see what this clock looks like. You may prefer the square outline of the `xclock` program:

>     xclock -geometry 150x150+5+5 &

Or perhaps a tiny digital clock at the bottom of your screen:

>     xclock -digital -geometry +10-10

`oclock` allows you to scatter more colors about, while `xclock` gives you more control over other aspects of the clock; see the manual pages for more information. To get a beep every half hour, invoke `xclock` with the -chime option.

### 11.4.7. Emacs

The X features in Emacs are getting spiffier and spiffier. They include pull-down menus, different typefaces for different parts of your window, and a complete integration of cut-and-paste functions with the X environment.

> #### NOTE

> Most distributions nowadays also carry XEmacs, a version of Emacs that integrates even better into the X Window System and has a much nicer and more user-friendly appearance. You might want to try it out. Most of the concepts here apply to XEmacs, too.

Let's start by defining some nice colors for different parts of the Emacs window. Try this command:

>     eggplant$ emacs  -bg ivory  -fg slateblue  -ms orangered  -cr brown

You are setting the background color, foreground color, mouse color, and cursor color respectively. The cursor is the little rectangle that appears in the window, representing what's called "point" in Emacs--the place where you type in text. We'll return to colors soon.

When you start Emacs, the menu bar on top and the scrollbar on the right side of the window stand out. See Figure 11-10.

#### Figure 11-10. Emacs window

The scrollbar works just like the `xterm` scrollbar. The menu bar offers a lot of common functions. Some editing modes, like C and TeX, have their own pull-down menus. The menus are not documented, so you will just have to experiment and try to figure out which Emacs functions they correspond to.

When you want to use a function that doesn't have a simple key sequence--or you've forgotten the sequence--the menus come in handy. For instance, if you rarely use a regular expression search (a quite powerful feature, well worth studying), the easiest way to invoke it is to pull down the Edit menu and choose Regexp Search.

Another useful menu item is Choose Next Paste on the Edit menu. This offers something you can't get any other way: a list of all the pieces of text you've cut recently. In other words, it shows you the kill ring. You can choose the text you want to paste in next, and the next time you press `C-y`, it's put into your buffer.

If you get tired of the scrollbar and the menu, put the following LISP code in your .emacs file to make them go away:

>     (if (getenv "DISPLAY")
>         (progn (menu-bar-mode -1)
>                (scroll-bar-mode -1))
>        )

The mouse is the next X feature with interesting possibilities. You can cut and paste text much the same way as in `xterm`. And you can do this between windows; if you see some output in an `xterm` you'd like to put in a file, you can copy it from the `xterm` and paste it into your Emacs buffer. Moreover, any text you cut the normal way (such as through `C-w`) goes into the same selection as text you cut with the mouse. So you can cut a few words from your Emacs buffer and paste them into an `xterm`.

The right mouse button works a little unusually. If you select text with the left mouse button, you can click once on the right mouse button to copy it. A second click on the right mouse button removes it. To paste it back, press the middle mouse button. The text goes just before the character the mouse is currently on. Make a mistake? That's all right; the undo command reverses it just as for any other Emacs function. (Choose Undo from the Edit menu or just press the `C-_` key.)

If you really love mouse work, you can define the buttons to execute any functions you want, just as with keys. Try putting the following command in your .emacs file. When you hold down the Shift key and press the left mouse button, a buffer for composing a mail message appears:

>     (define-key global-map [S-mouse-1] 'mail)

We don't recommend you redefine the existing mouse functions, but the Shift, Control, and Meta keys offer plenty of unused possibilities. Combine `S-`, `C-`, and `M-` any way you want in your definitions:

>     (define-key global-map [S-C-mouse-1] 'mail)

Now let's play around a bit with windows. Emacs has had windows of its own for decades, of course, long before the X Window System existed. So an Emacs window is not the same as an X window. What X considers a window, Emacs calls a frame.

How would you like to edit in two frames at once? Press `C-x 5 2`, and another frame appears. The new frame is simply another view onto the same editing session. You can edit different buffers in the two frames, but anything you do in one frame is reflected to the corresponding buffer in the other. When you exit Emacs by pressing `C-x` `C-c`, both frames disappear; if you want to close just one frame, press `C-x 5 0`.

To end our exploration of Emacs on the X Window System, we'll look at the exciting things you can do with colors. You can change these during an Emacs session, which makes it easy to play around with different possibilities. Press `M-x`, then type `set-background-color` and press the Enter key. At the prompt, type `ivory` or whatever other color you've chosen. (Remember, Emacs uses the convention `M-x` where we use Meta-x or Alt-x in the rest of the book.)

Be careful to make the foreground and background different enough so that you can see the text! In addition to `set-background-color`, Emacs offers `set-foreground-color`, `set-cursor-color`, and `set-mouse-color`.

These settings may seem idle play, but now they show their true colors when you let Emacs highlight different parts of your buffer in different ways. For instance, when you are programming in C or LISP, you can display strings, comments, function names, and keywords in different colors.

To set up color coding, you have to set `font-lock` mode. The easiest way to do this is in your .emacs start-up file; add lines like the following:

>     (require 'font-lock)
>     (setq global-font-lock-mode t)
>     (setq font-lock-maximum-decoration t)

These rather complicated commands tell each major mode to set the font lock whenever you open a buffer in that mode. So whenever you edit a file ending with the suffix .c, for instance, you automatically set the font lock.

Next, you want to play with the font faces, which are the different kinds of text defined by Emacs. Press `M-x` and enter the command `list-faces-display`. You'll see a list like the following:

>                    bold abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ
>             bold-italic abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ
>                 default abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ
>               highlight abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ
>                  italic abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ
>                modeline abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ
>                  region abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ
>     secondary-selection abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ
>               underline abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ

You can now set the background and foreground of each face interactively. Here is an example:

1. Enter `M-x set-face-background.`

2. Type `modeline` at the first prompt.

3. Type `lemonchiffon` at the second prompt.

You see the results immediately. Then set the foreground:

1. Enter `M-x set-face-foreground.`

2. Type `modeline` at the first prompt.

3. Type `green` at the second prompt.

No, that probably doesn't offer enough contrast for you to read the words. So do it again and use the color `maroon`. That looks better.

Find a buffer with C or LISP code in it and try setting each of the other faces. Faces are assigned rather arbitrarily to elements of the code. As you add colors, new dimensions will be revealed in your code. For instance, in C or C++ mode:

- Comments and preprocessor keywords appear in italic.

- Strings and include filenames appear in underline.

- Function names and defined variables appear in bold-italic.

It probably looks best to reserve the bolder colors for short, rarely seen pieces of text.

When you find a set of colors you like, hard-wire them into your .emacs file by using the LISP functions that correspond to the commands you've been experimenting with. Here's a sample set:

>     (set-background-color "ivory")
>     (set-foreground-color "slateblue")
>     (set-cursor-color "brown")
>     (set-mouse-color "orangered")
>     (set-face-foreground 'bold "black")
>     (set-face-background 'bold "lightpink")
>     (set-face-foreground 'bold-italic "red")
>     (set-face-background 'bold-italic "wheat")
>     (set-face-foreground 'italic "darkolivegreen")
>     (set-face-background 'modeline "lemonchiffon")
>     (set-face-foreground 'modeline "maroon")
>     (set-face-foreground 'underline "violet")

You can also set colors in your .Xdefaults file, but that takes a little more effort, so we won't bother to explain it here.

### 11.4.8. Ghostview: Displaying PostScript

Adobe PostScript, as a standard in its own right, has become one of the most popular formats for exchanging documents in the computer world. Many academics distribute papers in PostScript format. The Linux Documentation Project offers its manuals in PostScript form, among others. This format is useful for people who lack the time to format LaTeX input, or who have immense network bandwidth for transferring files. When you create documents of your own using `groff` or TeX, you'll want to view them on a screen before you use up precious paper resources by printing them.

Ghostview, a GNU application, offers a pleasant environment for viewing PostScript on the X Window System. It's very simple; invoke it with the name of the file to be displayed, for instance:

>     eggplant$ ghostview article.ps

The Ghostview window is huge; it can easily take up most of your screen. The first page of the document is displayed with a vertical scrollbar on the right and a horizontal one on the bottom. Menu options appear on the left side of the window, and page numbers just to their right.

Like most X applications, Ghostview offers both menu options and keys (accelerators) for common functions. Thus, to view the next page, you can pull down the Page menu and choose the Next option. Or you can just press the space bar.

To go back to the previous page, choose Previous from the Page menu. To go to any page you want, press the middle mouse button on its number in the number column. To exit, choose Quit from the File menu or just press `q`.

Documents from different countries often use different page sizes. The Ghostview default is the standard U.S. letter size (this can be overridden by comments in the PostScript file). You can specify a different size on the command line:

>     eggplant$ ghostview -a3 article.ps

or in your .Xdefaults file:

>     Ghostview*pageMedia:            A3

Finally, you can also choose a different size at runtime from the Media menu.

Ghostview lets you enlarge or reduce the size of the page, a useful feature for checking the details of your formatting work. (But be warned that fonts on the screen are different from the fonts on a printer, and therefore the exact layout of characters in Ghostview will not be the same as that in the hard copy.) To zoom in on a small part of the page, press any mouse button on it. (The right mouse button enlarges the most; the left mouse button the least.)

You can also change the default size for displaying the whole document by using the Magstep menu. The higher the number you choose, the more the document is enlarged. Negative numbers reduce the size of the document.

To print a page, choose Print from the File menu or press `p` anywhere in the window. You are prompted to make sure that you've chosen the right printer; you can erase what is shown there and enter a different name. The name shown comes from your environment. So, if your printer is named doorway, you should have issued a shell command in your startup file like:

>     export PRINTER=doorway

You can also print several pages. Select individual ones by clicking on their numbers with the middle mouse button. Or select the first page with the left mouse button, and the last page with the right mouse button; the whole range of pages will be printed when you press `p`.

> #### NOTE

> KDE comes with its own version of Ghostview, called `kghostview`, which is really just Ghostview with a more user-friendly interface and a nicer appearance. You can run `kghostview` even if you do not plan to run the rest of KDE.

> Another option would be to use `gv`, which has become quite popular lately.

### 11.4.9. xman: A Point-and-Click Interface to Manual Pages

Manual pages, read through the `man` command, are the ultimate authority on a Unix system. Other books can describe a significant percentage of any given command's functions--and often describe them in a more readable fashion--but only the manual page has all the details. See the section "Section 4.12, "Manual Pages"" in Chapter 4, "Basic Unix Commands and Concepts" for basic information.

Now there's a simple X interface to manual pages: the `xman` command. As befits a tool that displays documents, it contains a pretty good description of itself. In order to see this documentation clearly, start up the program with a large page size:

>     eggplant$ xman -pagesize 650x600

What you see first is a tiny box with three buttons. Click on the Manual Page button to bring up the main screen, where you'll do most of your work.

Now you see the `xman` documentation. You'll have plenty of time to read this; for now, just pull down the Options menu and choose Search, or press Ctrl-S. (You can also display the options menu by holding down the Control key and pressing the left mouse button.) In the box that pops up, type in a command or function you'd like to read about, then press the Enter key. The contents of the main window are replaced by the corresponding manual page.

If you don't know what to look for, try pulling down the Sections menu or pressing the Control key along with the middle button. Choose a section from the menu that appears. You'll see a long list of manual pages. Click the left button on one of them, and the document will be displayed.

Another time-honored way to look for information is through the `apropos` command (discussed already in the section "Section 4.12, "Manual Pages"" in Chapter 4, "Basic Unix Commands and Concepts"). Press Ctrl-S again, type in a word about a subject you're interested in, and press the Apropos button. If any manual pages match that word, their names will be displayed along with short descriptions. Unfortunately, you can't call up their manual pages by clicking on them; that little convenience was left out of `xman`. You have to press Ctrl-S and type in the page that looks interesting.

Within a manual page, scrolling is easy. Use the space bar or `f` to move down a page, `b` to move up. You can also use the scrollbar, just as in `xterm`.

Now you can read the documentation! Press the Help button on the small window that appeared when you started `xterm`. To exit the program, press Ctrl-Q or the Quit button, or choose Quit from the Options menu.

If you think that `xman` is still too bare-bones and not much of an improvement over the command-line `man` command, you can try one of its more advanced companions. For example, `tkman` has a much nicer user interface and features advanced navigation possibilities. The KDE help system, `kdehelp`, can display manual and info pages in addition to its own HTML pages and thus unifies the three major documentation formats on Linux.

Copyright © 2001 O'Reilly & Associates. All rights reserved.